<?php

namespace App\Http\Requests\Backend;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * Class EditSchool
 * @package App\Http\Requests\Backend
 */
class EditSchool extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => [
                'required',
                'string',
                Rule::unique('schools')->ignore((int)trim(strrchr(Request()->path(), '/'),'/'))
            ],
            'detail_address' => 'required|string',
            'contact_name' => 'required|string',
            'contact_phone' => ['required', 'regex:/^1[3|4|5|7|8|9][0-9]{9}$/', 'string'],
            'areaId' => ['required', 'array', 'size:3'],
            'dev_code' => 'string|nullable',
            'key' => 'string|nullable',
            'key_id' => 'string|nullable',
            'objectid' => 'string|nullable',
            'status' => 'integer|required'
        ];
    }

    /**
     * @return array
     */
    public function attributes()
    {
        return [
            'name' => '学校名称',
            'detail_address' => '学校详细地址',
            'contact_name' => '联系人',
            'contact_phone' => '联系电话',
            'areaId' => '学校地址',
            'dev_code' => '开发者标识',
            'key' => 'key',
            'key_id' => 'key_id',
            'objectid' => '智慧校园id',
            'status' => '状态'
        ];
    }

    /**
     * @return array
     */
    public function messages()
    {
        return [
            'name.unique' => '已存在相同的:attribute',
            'name.required' => '请填写:attribute',
            'detail_address.required' => '请填写:attribute',
            'contact_name.required' => '请填写:attribute',
            'contact_phone.required' => '请填写:attribute',
            'contact_phone.regex' => ':attribute格式错误',
            'areaId.required' => '请选择:attribute',
            'areaId.size' => ':attribute参数错误',
            'areaId.array' => ':attribute数据类型错误',
            'name.string' => ':attribute数据类型错误',
            'detail_address.string' => ':attribute数据类型错误',
            'contact_name.string' => ':attribute数据类型错误',
            'contact_phone.string' => ':attribute数据类型错误',
            'dev_code.string' => ':attribute数据类型错误',
            'key.string' => ':attribute数据类型错误',
            'key_id.string' => ':attribute数据类型错误',
            'objectid.string' => ':attribute数据类型错误',
            'status.string' => ':attribute数据类型错误',
            'status.required' => '请填写:attribute'
        ];
    }
}
